package nc.ui.ar.badacc;

import java.util.ArrayList;
import java.util.Map;

import nc.ui.arap.service.IRemoteCallItem;
import nc.vo.arap.badacc.DstlFactorVO;
import nc.vo.arap.mapping.ArapBadAccItemVO;
import nc.vo.arap.mapping.ArapItemUtils;
import nc.vo.arap.mapping.ArapItemVO;
import nc.vo.arap.service.ServiceVO;
import nc.vo.pub.BusinessException;

public class ArapItemInitCall implements IRemoteCallItem {

	protected ServiceVO serviceVO=null;
	
	private String code;

	public ServiceVO getServiceVO() {
		if(serviceVO==null){
			serviceVO = new ServiceVO();
			serviceVO.setClassname("nc.itf.arap.badacc.IArapDstlCaseQuery");
			serviceVO.setMethodname("queryAllDstlFactorVOs");
			serviceVO.setParamtype(new Class[] {});
			serviceVO.setParam(new Object[] {});
			code = serviceVO.getCode();
		}
		return serviceVO;
	}

	public void handleResult(Map<String, Object> datas)
			throws BusinessException {
		DstlFactorVO[] factors =(DstlFactorVO[]) datas.get(code);

		for (DstlFactorVO factor : factors) {
			ArapBadAccItemVO item = new ArapBadAccItemVO(factor
					.getPk_dstlfactor(), factor.getName(), factor.getRefname(),
					factor.getDatatype(), factor.getReftype(), factor
							.getOperator(), factor.getCode(), factor
							.getTablecode(), factor.getTablekey(), factor
							.getCodekey(), factor.getNamekey(), factor
							.getJnkey(), factor.getTablepk(), factor
							.getParentkey());
			if (ArapItemUtils.getTypeMap().get(item.getDatatype()) == null) {
				ArapItemUtils.getTypeMap().put(item.getDatatype(), new ArrayList<ArapItemVO>());
			}
			ArapItemUtils.getItemMap().put(item.getPk_factor(), item);
			ArapItemUtils.getTypeMap().get(item.getDatatype()).add(item);
			ArapItemUtils.getBadaccLs().add(item);
		}

	}


}
